package com.fxl.controller;

import com.fxl.entity.User;
import com.fxl.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/user")
@Api(value = "用户管理接口", tags = "用户管理接口", description = "用户相关的增删改查操作")
public class HelloController {

    @Autowired
    private UserService userService;

    @PostMapping("/getAllUsers")
    @ApiOperation(value = "获取所有用户", notes = "获取系统中所有用户的信息")
    public List<User> getAllUsers() {
        List<User> users = userService.getAllUsers();
        return users;
    }

    @PostMapping("/getUserById")
    @ApiOperation(value = "根据ID获取用户", notes = "根据用户ID获取单个用户信息")
    public User getUserById(Integer id) {
        User user = userService.getUserById(id);
        return user;
    }
    @PostMapping("/addUser")
    @ApiOperation(value = "添加用户", notes = "添加一个新的用户")
    public User addUser(User user) {
        return userService.addUser(user);
    }

    @PostMapping("/deleteUser")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id", value = "用户ID", required = true),
            @ApiImplicitParam(name = "username", value = "用户账号", required = true)
       }
    )
    @ApiOperation(value = "删除用户3", notes = "根据用户ID删除指定用户3")
    public String deleteUser3(Integer id2,String username2) {
        userService.deleteUser(id2);
        return "User with id " + id2 + " has been deleted successfully.";
    }
}


